package cn.baage;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;
import java.util.concurrent.TimeUnit;

/**
 * @ClassName Controller
 * @Description TODO
 * @Author baage
 * @Date 2025/6/23
 */
@RestController
public class TestController {

    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    @Autowired
    private DataService dataService;

    private final String key = "queuing:";

    private boolean startStatus = false;

    @GetMapping("/start")
    public void start() {
        if (startStatus) {
            return;
        }
        startStatus = true;
        String curData = dataService.getCurData();
        redisTemplate.opsForValue().set(key + curData, curData);
        redisTemplate.expire(key + curData, 30, TimeUnit.SECONDS);
    }


    @GetMapping("/get")
    public Map<String, Object> getCurrentUser() {
        String curData = dataService.getCurData();
        Map<String, Object> data = new HashMap<>();
        data.put("curData", curData);
        return data;
    }


    @GetMapping("/over")
    public void overCurrentUser(String value) {
        dataService.nextData(value);
    }

}
